@using Microsoft.AspNetCore.Components.Web
@namespace BlazorApp4.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="~/" />
    <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
    <link href="css/site.css" rel="stylesheet" />
    <link href="BlazorApp4.styles.css" rel="stylesheet" />
    <component type="typeof(HeadOutlet)" render-mode="Server" />
</head>
<body>
    @RenderBody()

    <div id="blazor-error-ui">
        <environment include="Staging,Production">
            An error has occurred. This application may no longer respond until reloaded.
        </environment>
        <environment include="Development">
            An unhandled exception has occurred. See browser dev tools for details.
        </environment>
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>

    <script src="_framework/blazor.server.js"></script>

    <script>

        function triggerFileDownload(fileName, uri) {
            var url = uri + "files/" + fileName;
            console.log(url);
            const anchorElement = document.createElement('a');
            anchorElement.href = url;
            anchorElement.download = fileName ?? '';
            anchorElement.click();
            anchorElement.remove(); 
        }


        function triggerFileDownloadViaPath(fileName, uri) {
            var url = uri + fileName;
            console.log(url);
            const anchorElement = document.createElement('a');
            anchorElement.href = url;
            anchorElement.download = fileName ?? '';
            anchorElement.click();
            anchorElement.remove();
        }

        function getIpAddress() {
            return fetch("https://jsonip.com/")
                .then((response) => response.json())
                .then(data => data.ip);
        }

        //窗口滚到最下面 参考https://www.cnblogs.com/pxblog/p/12595137.html#:~:text=js%E6%8E%A7%E5%88%B6%E6%BB%9A%E5%8A%A8%E6%9D%A1%E5%9C%A8%E6%9C%80%E5%BA%95%E9%83%A8%E4%BD%8D%E7%BD%AE%201,window.scrollTo%20%280%2C%20document.body.scrollHeight%29
        function scrollBottom(elementId) {
            //window.scrollTo(0, document.body.scrollHeight)
            var element = document.getElementById(elementId);
			if (element != null)
				element.scrollTop = element.scrollHeight;
        }


        function requestNotificationPermission() {
            return new Promise(function (resolve, reject) {
                if (Notification.permission === "granted") {
                    resolve();
                } else if (Notification.permission !== "denied") {
                    Notification.requestPermission().then(function (permission) {
                        if (permission === "granted") {
                            resolve();
                        } else {
                            reject();
                        }
                    });
                } else {
                    reject();
                }
            });
        }

        function showNotification(title, message) {
            if (Notification.permission === "granted") {
                var notification = new Notification(title, {
                    body: message,
                    icon: "path/to/icon.png"
                });
                notification.onclick = function () {
                   console.log(title + message);
                   window.focus();
                };
            }
        }

        function playNotificationAudio(element) {
            console.log(element);
            //var audio = document.getElementById("notificationAudioById");
            //console.log(audio);
            element.play();

        }
		
		// 获取设备类型
		function getDeviceType() {
		  var userAgent = navigator.userAgent.toLowerCase();
		  var deviceType = "";
		
		  if (userAgent.indexOf("mobile") !== -1) {
		    deviceType = "mobile";
		  } else {
		    deviceType = "desktop";
		  }
		
		  return deviceType;
		}
    </script>
</body>
</html>
